import jdk.swing.interop.SwingInterOpUtils;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-13
 * Time: 11:21
 */
public class Test {
    public static void main22(String[] args) {
        //求一个整数，在内存当中存储时，二进制1的个数。
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int sum = 0;
        /*for (int i = 0; i < 32; i++) {
            *//*int ret = num & 1;
            num = num >> 1;
            sum += ret;*//*
            if(((num >>> i) & 1) == 1){
                sum++;
            }
        }*/
        while( num != 0){
            if((num & 1) == 1){
                sum++;
            }
            num = num >>>1;
        }
        /*while(num != 0) {
            num = num & (num - 1);
            sum++;
        }*/
        System.out.println(sum);
    }
    public static void main21(String[] args) {
        /*
        给定两个数，求这两个数的最大公约数
        例如：
        输入：20 40
        输出：20
         */
        Scanner scanner = new Scanner(System.in);
        int num1 = scanner.nextInt();
        int num2 = scanner.nextInt();
        int num3 = num1 % num2;
        //暴力穷举
        /*for (int i = 1; i <= (num1>num2?num2:num1); i++) {
            if(num1 % i == 0&& num2 % i == 0){
                ret = i;
            }
        }*/
        //辗转相除法
        while(num3 > 0){
            num1 = num2;
            num2 = num3;
            num3 = num1 % num2;
        }
        System.out.println(num2);
    }
    public static void main20(String[] args) {
        //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
        double sum1 = 0;
        double sum2 = 0;
        /*for (int i = 1; i < 100; i += 2) {
            sum1 += 1.0/i;
        }
        for (int i = 2; i <= 100; i += 2) {
            sum2 += 1.0/i;
        }
        double sum = sum1 - sum2;
        System.out.println(sum);*/
        int flag = 1;
        double sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += 1.0 * flag / i;
            flag = -flag;
        }
        System.out.println(sum);
    }
    public static void main19(String[] args) {
        /*
        求出0～n之间的所有“水仙花数”并输出。
        (“水仙花数”是指一个三位数，其各位数字的立方和确好等于该数本身，
        如；153＝1^3＋5^3＋3^3，则153是一个“水仙花数“。）
         */
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int tmp = i;
            int count = 0;
            int sum = 0;
            //判断位数
            while(tmp != 0){
                tmp /= 10;
                count++;
            }
            //计算每一位的次方和
            tmp = i;
            while(tmp > 0){
                sum += Math.pow(tmp % 10,count);
                tmp /= 10;
            }
            if(i == sum){
                System.out.println(i);
            }
        }
    }
    public static void main18(String[] args) {
        /*
    多组输入，一个整数（2~20），表示输出的行数，也表示组成“X”的反斜线和正斜线的长度。
    输出描述： 针对每行输入，输出用“*”组成的X形图案。
     */
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            for(int i = 0;i < a;i++){
                for(int j = 0;j < a;j++){
                    if(i == j || i + j == a-1){
                        System.out.print("*");
                    }else{
                        System.out.print(" ");
                    }
                }
                System.out.print("\n");
            }
        }
    }
    public static void main17(String[] args) {
        //2.给定一个数字，判定一个数字是否是素数
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入：");
        int num = scanner.nextInt();
        /*int flag = 0;
        if(num == 0 || num == 1){
            System.out.println(num + "不是素数");
        }
        for (int i = 2; i < num; i++) {
            if(num % i == 0){
                flag++;
            }
        }
        if(flag == 0){
            System.out.println(num + "是素数");
        }else {
            System.out.println(num + "不是素数");
        }*/
        int i = 2;
        for (; i <= Math.sqrt(num); i++) {
            if(num % i == 0){
                System.out.println(num + "不是素数");
                break;
            }
        }
        if(i > Math.sqrt(num)){
            System.out.println(num + "是素数");
        }
    }
    public static void main16(String[] args) {
        /*
        认识运算符等_作业
        1.编写程序数一下 1到 100 的所有整数中出现多少个数字9
         */
        int count = 0;
        for (int i = 1; i <= 100 ; i++) {
            //判断个位是否为9
            if(i % 10 == 9){
                count++;
            }
            //判断十位是否为9
            if(i / 10 == 9){
                count++;
            }
        }
        System.out.println(count);
    }
    public static void main15(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入姓名：");
        String name = scanner.nextLine();
        System.out.println(name);
        System.out.println("请输入年龄");
        int age = scanner.nextInt();
        System.out.println(age);
        System.out.println("请输入价格：");
        float f = scanner.nextFloat();
        System.out.println(f);
    }
    public static void main14(String[] args) {
        /*
        键盘输入：Scanner scanner = new Scanner(System.in);
                int n = scanner.nextInt();
         */

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        int sum = 0;
        for (int i = 1; i <= n; i++) {
            int ret = 1;
            for (int j = 1; j <= i; j++) {
                ret *= j;
            }
            sum += ret;
        }
        System.out.println(sum);

    }
    public static void main12(String[] args) {
        /*
        for循环：
        for(表达式1;布尔表达式2;表达式3){
            表达式4；
        }
         */

      /*  int ret = 1;
        for (int i = 1; i <= 5 ; i++) {
            ret *= i;
        }
        System.out.println(ret);*/

        int sum = 0;
        for (int i = 1; i <= 5; i++) {
            int ret = 1;
            for (int j = 1; j <= i; j++) {
                ret *= j;
            }
            sum += ret;
        }
        System.out.println(sum);
    }
    public static void main11(String[] args) {
        /*
        break:跳出整个循环
        continue:跳出当前循环，进入下一个循环
         */
        //找到1~100中，第一个能被3和5整除的数
        int i =1;
        while(i<=100)
        {
            if(i % 15 == 0)
            {
                System.out.println(i);
                i++;
                break;
            }
            i++;
        }
        i = 1;
        //找到1~100中，所有能被3和5整除的数
        while(i<=100){
            if(i % 15 == 0){
                System.out.println(i);
                i++;
                continue;
            }
            i++;
        }
    }
    public static void main10(String[] args) {
        /*
        循环语句:while for do...while
        while(循环表达式){
            //循环语句
        }
         */
 /*       int i = 1;
        int ret = 0;
        while(i<=5){
            ret +=i;
            i++;
        }
        System.out.println(ret);*/
        int j = 1;
        int i = 1;
        int sum = 0;
        while(j <= 5){
            int ret = 1;
            while(i <= j){
                ret *= i;
                i++;
            }
            sum += ret;
            j++;
        }
        System.out.println(sum);
    }
    public static void main9(String[] args) {
        /*
        表达式只能是：byte char short int String常量串 枚举类型
        switch(表达式){
            case 常量值1:
                语句1;
                break;
            case 常量值2:
                语句2;
                break;
            ...
            default:
                都不满足执行的语句;
                break;
        }
         */
        int day = 1;
        switch(day){
            case 1:
                System.out.println("星期一");
                break;
            case 2:
                System.out.println("星期二");
                break;
            default:
                System.out.println("其他");
                break;
        }
    }
    public static void main8(String[] args) {
        /*
        分支结构：if语句  switch语句
        if(布尔表达式1){
            //语句
        }else if(布尔表达式2){
            //语句
        }
        else{
            //语句
        }
         */
        int i = 10;
        if(i % 2 == 0) {
            System.out.println("偶数");
        }else{
            System.out.println("奇数");
        }

        boolean b = false;
        if(b == true){
            System.out.println("真");
        }else{
            System.out.println("假");
        }

        int a = 1;
        if(a <= 5){
            if(a == 3){
                System.out.println("a == " + a);
            }else{
                System.out.println("a != " + a);
            }
        }

    }
    public static void main7(String[] args) {
        /*
        顺序结构：按照书写顺序依次执行
         */
        System.out.println("hhh");
        System.out.println("aaa");
        System.out.println("ooo");
    }
    public static void main6(String[] args) {
        /*
        条件运算符：表达式1 ? 表达式2 : 表达式3
        表达式1：true --> 表达式2
        表达式1：true --> 表达式3
         */
        int a = 10;
        int b = 20;
        int c = a > b ? 10 : 20;
        System.out.println(c);

        boolean d = true == true ? true == false ? true : false :true;
        System.out.println(d);
    }
    public static void main5(String[] args) {
        /*
        移位运算：<< >> >>>
        左移：m<<1 m<<2 .... m<<n --> m*2^n 右侧补0
        右移：m>>1 m>>2 .... m>>n --> m/2^n 符号位为1 则补1 符号位为0 则补0
        无符号右移：m>>>1 左侧补0
         */
    }
    public static void main4(String[] args) {
        /*
        按位与&：有0则为0
        按位或|：有1则为1
        按位异或^：相同为0 相异为1
        按位取反~：1->0 0->1
        不存在短路:&：表达式1为假也会执行表达式2
                 |：表达式1为真也会执行表达式2
         */
        int a = 10;
        int b = 20;
        System.out.println(a > b & a == 20);
        System.out.println(a < b & a == 20);
        System.out.println(a < b & a == 10);
        System.out.println(a > b & a == 10);

        System.out.println(a > b | a == 20);
        System.out.println(a < b | a == 20);
        System.out.println(a < b | a == 10);
        System.out.println(a > b | a == 10);

        //验证不存在短路
        System.out.println(a > b & a/0 == 0);
        System.out.println(a < b | a/0 == 0);
    }
    public static void main3(String[] args){
        /*
        逻辑运算符：&& ||
        布尔表达式1 && 布尔表达式2
        其结果为boolean类型
        短路与 和 短路或
        短路与：表达式1 为假，表达式2 就不会执行
        短路或：表达式1 为真，表达式2 就不会执行
         */
        int a = 10;
        int b = 20;
/*
        System.out.println(a < b && a == 10);
        System.out.println(a > b && a == 10);
        System.out.println(a > b && a == 20);
        System.out.println(a < b && a == 20);

        System.out.println(a < b || a == 10);
        System.out.println(a > b || a == 10);
        System.out.println(a < b || a == 20);
        System.out.println(a > b || a == 20);
*/
        //验证短路
        System.out.println(a > b && 10/0 == 0);
        System.out.println(a < b || 10/0 == 0);
        System.out.println(a < b || 10/0 == 0);

    }
    public static void main2(String[] args){
        /*
        关系运算符：== != < > >= <=
        其结果为true/false
         */
        int a = 10;
        int b = 20;
        System.out.println(a == b);
        System.out.println(a != b);
        System.out.println(a > b);
        System.out.println(a < b);
        System.out.println(a >= b);
        System.out.println(a <= b);

    }
    public static void main1(String[] args){
        /*
        自增自减运算符：++ --
        前置++/-- :先自加/减 再赋值
        后置++/-- :先赋值 再自加/减
         */
        int a = 10;
        int b = a++;
        int c = ++a;
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
    }

}
